package function;

import java.io.IOException;
import java.util.Random;
import java.util.Scanner;

/**
 * @version 1.0
 * @program: math test
 * @description: 试卷题目
 * @author: Kishan Liu
 * @create: 2021-12-09 17:52
 **/
public class MathematicsExamination {
    static  public void question(String id) throws IOException {
        long startTime = System.currentTimeMillis();
        int count = 0;
        int last=0;
        for (int i = 1; i < 11; i++) {
           for (;;){
               Random rand3 = new Random();
               if (rand3.nextInt(4)+1!=last){
                   last=rand3.nextInt(4)+1;
                   break;
               }
           }
            int answer = 0;
            switch (last) {
                case 1:
                    for (; ; ) {
                        Random rand1 = new Random();
                        Random rand2 = new Random();
                        int first = rand1.nextInt(100) + 1;
                        int second = rand2.nextInt(100) + 1;
                        answer = first + second;
                        if (answer < 100) {
                            System.out.print("第" + i + "题：" + first + "+" + second + "=");
                            break;
                        }
                    }
                    break;
                case 2:
                    for (; ; ) {
                        Random rand1 = new Random();
                        Random rand2 = new Random();
                        int first = rand1.nextInt(100) + 1;
                        int second = rand2.nextInt(100) + 1;
                        answer = first - second;
                        if (answer > 0) {
                            System.out.print("第" + i + "题：" + first + "-" + second + "=");
                            break;
                        }
                    }
                    break;
                case 3:
                    for (; ; ) {
                        Random rand1 = new Random();
                        Random rand2 = new Random();
                        int first = rand1.nextInt(100) + 1;
                        int second = rand2.nextInt(100) + 1;
                        if (first % second == 0 && first / second < 100 && first / second > 0) {
                            System.out.print("第" + i + "题：" + first + "/" + second + "=");
                            answer = first / second;
                            break;
                        }
                    }
                    break;
                case 4:
                    for (; ; ) {
                        Random rand1 = new Random();
                        Random rand2 = new Random();
                        int first = rand1.nextInt(100) + 1;
                        int second = rand2.nextInt(100) + 1;
                        answer = first * second;
                        if (answer > 0 && answer < 100) {
                            System.out.print("第" + i + "题：" + first + "*" + second + "=");
                            break;
                        }
                    }
            }
            Scanner in = new Scanner(System.in);
            int userAnswer = in.nextInt();
            if (userAnswer == answer)
                count++;
        }
        long endTime = System.currentTimeMillis();
        int runTime = (int) (endTime - startTime) / 1000;
        String evaluation ;
        if (count >= 8 && runTime <= 90)
            evaluation = "优";
        else if (count >= 80)
            evaluation = "良";
        else if (count >= 60 && runTime <= 150) {
            evaluation = "及格";
        } else {
            evaluation = "差";
        }
        DataBase.writeData(id,count*10,runTime,evaluation);
    }
}
